import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.preprocessing import MinMaxScaler
from sklearn import svm
import numpy as np

def draw_decision_function(clf,ax):
    SETOSA = 0  # this is one of the three classes of irises
    # 2D meshgrid
    xx, yy = np.meshgrid(np.linspace(0, 1, 100), np.linspace(0, 1, 100))
    # Decision function of each mesh coordiante 
    Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()]) 
    Z = Z[:,SETOSA].reshape(xx.shape)  # reshape to 2D
    # Paints each mesh decision value
    ax.pcolormesh(xx, yy, -Z, cmap=plt.cm.RdBu) 
    return

iris = load_iris()
X = iris.data[:,0:2]
y = iris.target
scaler = MinMaxScaler()
scaler.fit(X)
X = scaler.transform(X)

fig, axs = plt.subplots(1,4, figsize=(18,3))
for i,ax,C,gamma in zip(range(4), axs, [0.01, 0.1, 0.5, 1],[3,7,10,10]):
    clf = svm.SVC(kernel='rbf', gamma=gamma, C=C)
    clf.fit(X, y) 
    
    draw_decision_function(clf,ax)
    for target, color, marker in zip(range(2),['w','y'],['o','^']):
        ax.scatter(X[y==target,0], X[y==target,1],c=color, 
                   marker=marker, label='class '+format(target))
        ax.set_title('SVM, C: ' + format(C) + ', gamma: '+str(gamma)) 
  
plt.show()
